// 题意：区间染色，最后统计每个颜色的线段个数
//
// 题解：线段树。这里最后统计的时候O(n)统计。
//

#include <iostream>
#include <algorithm>
#include <vector>

struct node { int l; int r; int co; };

int const maxn = 8001;
int color[maxn];
int count[maxn];
int n;
std::vector<node> seg_tree(4 * maxn);

void init_seg_tree(int index, int l, int r)
{
	seg_tree[index].l = l; seg_tree[index].r = r;
	seg_tree[index].co = -1;
	if (l < r) {
		int mid = (l + r) / 2;
		init_seg_tree(index * 2, l, mid);
		init_seg_tree(index * 2 + 1, mid + 1, r);
	}
}

void insert_seg_tree(int index, int l, int r, int co)
{
	if (seg_tree[index].l == l && seg_tree[index].r == r) {
		seg_tree[index].co = co;
		return;
	}
	if (seg_tree[index].co != -1) {
		seg_tree[index * 2].co = seg_tree[index * 2 + 1].co = seg_tree[index].co;
		seg_tree[index].co = -1;
	}

	int mid = (seg_tree[index].l + seg_tree[index].r) / 2;
	if (r <= mid)
		insert_seg_tree(index * 2, l, r, co);
	else
	if (l > mid)
		insert_seg_tree(index * 2 + 1, l, r, co);
	else {
		insert_seg_tree(index * 2, l, mid, co);
		insert_seg_tree(index * 2 + 1, mid + 1, r, co);
	}

}

void push_down(int index, int l, int r)
{
	if (seg_tree[index].l == seg_tree[index].r) {
		color[seg_tree[index].l] = seg_tree[index].co;
		return;
	}
	if (seg_tree[index].co != -1)
		seg_tree[index * 2].co = seg_tree[index * 2 + 1].co = seg_tree[index].co;

	int mid = (l + r) / 2;
	push_down(index * 2, l, mid);
	push_down(index * 2 + 1, mid + 1, r);
}

int main()
{
	std::ios::sync_with_stdio(false);
	int const len = 8000;
	while (std::cin >> n) {
		init_seg_tree(1, 0, len);

		int max_c = 0;
		for (int i = 0, l, r, c; i < n; i++) {
			std::cin >> l >> r >> c;
			max_c = std::max(max_c, c);
			insert_seg_tree(1, l, r - 1, c);
		}

		push_down(1, 0, len);

//		for (int i = 0; i < 5; i++) std::cerr << color[i] << ' '; std::cerr << '\n';

		std::fill(count, count + len + 1, 0);
		int c = color[0];
		for (int i = 1; i <= len; i++)
			if (color[i] != color[i-1]) {
				count[c]++;
				c = color[i];
			}
		count[c]++;

		for (int i = 0; i <= max_c; i++)
			if (count[i])
				std::cout << i << ' ' << count[i] << '\n';
		std::cout << '\n';
	}
}

